﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Micro.SMSGatWay.Core.Repository;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Micro.SMSGatWay.Core.Extensions
{
    public static class EntityFrameworkCoreExtension
    {
        public static void AddEntityFrameWorkCore(this IServiceCollection services, string dbConnectString="",string version="")
        {
            if(string.IsNullOrEmpty((dbConnectString)))
               throw new Exception("数据库连接不能为空！");
            if(string.IsNullOrEmpty(version))
                throw new Exception("数据库版本号连接不能为空！");
            services.AddDbContextPool<SmsApplicationContext>(s =>
                s.UseMySql(dbConnectString, ServerVersion.Parse(version)));

        }
    }
}
